<template>
  <div>
    <article class="main-breadcrumb">
      <el-breadcrumb separator="/" class="main-breadcrumb-wrap">
        <el-breadcrumb-item>
          <span class="main-breadcrumb-home">设备巡检</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <span class="main-breadcrumb-home">巡检任务</span>
        </el-breadcrumb-item>
        <el-breadcrumb-item>
          <span class="main-breadcrumb-home" @click="crumbsClick"
            >巡检结果</span
          >
        </el-breadcrumb-item>
        <el-breadcrumb-item v-if="typeDialog">
          <span class="main-breadcrumb-sp">{{ crumbsStatus }}</span>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </article>
    <div class="nx-content" v-if="!typeDialog">
      <div class="flex-bet">
        <div class="left-title flex">
          <el-button type="primary" @click="handleReturn()"
            >返回巡检任务</el-button
          >
        </div>
        <el-form
          ref="searchForm"
          :inline="true"
          :model="searchForm"
          class="demo-form-inline"
        >
          <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <NxTable
        :table-cols="tableCols"
        :table-data="tableData"
        class="table-wrap"
      >
        <template slot="inspectionImage" slot-scope="scope">
          <el-image
            style="height: 50px"
            :src="scope.row.inspectionImage"
            :preview-src-list="[scope.row.inspectionImage]"
            fit="contain"
          >
          </el-image>
        </template>
        <template slot="status" slot-scope="scope">
          <span v-if="scope.row.status == 0">未开始</span>
          <span v-if="scope.row.status == 1">进行中</span>
          <span class="nx-success" v-if="scope.row.status == 2">已完成</span>
          <span class="nx-del" v-if="scope.row.status == 3">已失败</span>
        </template>
      </NxTable>
    </div>
  </div>
</template>
<script>
import NxTable from "@/components/NxTable.vue";
import { getInspectionTaskResults } from "@/api/inspection";

export default {
  components: {
    NxTable,
  },
  // 表格数据
  data() {
    return {
      // 查询字段
      searchForm: {
        id: "",
      },
      // 表格字段
      tableCols: [
        {
          label: "巡检点名称",
          prop: "name",
          align: "center",
        },
        {
          label: "巡检图片",
          slot: "inspectionImage",
          align: "center",
        },
        {
          label: "开始时间",
          prop: "startDate",
          align: "center",
        },
        {
          label: "结束时间",
          prop: "endDate",
          align: "center",
        },
        {
          label: "巡检状态",
          slot: "status",
          align: "center",
        },
        {
          label: "错误信息",
          slot: "errorMsg",
          align: "center",
        },
      ],
      tableData: [],
      crumbsStatus: "", // 三级面包屑名称
      typeDialog: false,
    };
  },
  // 初始化加载
  mounted() {
    // 查询
    this.getList();
  },
  // 自定义方法
  methods: {
    // 查询
    onSubmit() {
      this.getList();
    },
    // 重置
    resetForm() {
      this.searchForm = {
        id: "",
      };

      this.onSubmit();
    },
    // 查询列表
    getList() {
      this.searchForm.id = this.$route.query.inspectionTaskId;
      getInspectionTaskResults(this.searchForm).then((res) => {
        if (res.code == 200) {
          this.tableData = res.data;
        }
      });
    },

    // 编辑添加取消关闭
    closeAddEdit() {
      this.typeDialog = false;
    },
    // 面包屑
    crumbsClick() {
      this.typeDialog = false;
    },
    // 返回
    handleReturn() {
      this.$router.push({
        path: `/inspection/inspectionTask`,
        query: {},
      });
    },
  },
};
</script>
<style lang="less" scoped>
.main-breadcrumb {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 76px;
  border-bottom: solid 20px #f2f2f2;
  padding-left: 20px;
  .main-breadcrumb-wrap {
    font-size: 16px;
    line-height: 68px;
    .main-breadcrumb-home {
      cursor: pointer;
      color: #666666;
      font-weight: bold;
    }
    .main-breadcrumb-sp {
      color: #666666;
      font-weight: bold;
    }
  }
}
</style>